package com.fw.ui.view.profile.merchant.event;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fw.service.bean.SearchCriteriaBean;
import com.fw.ui.bao.PropertyBAO;
import com.fw.ui.util.UICommonUtils;
import com.fw.ui.util.VaadinApplicationObjectSupport;
import com.fw.ui.view.event.AbstractButtonClickListener;
import com.fw.ui.view.profile.SearchMerchantProfileView;
import com.vaadin.ui.Button.ClickEvent;

@Component
@Scope(SCOPE_PROTOTYPE)
public class SearchMerchantProfileClearButtonClickListener extends AbstractButtonClickListener {

    private static final long serialVersionUID = 1L;

    @Autowired
    protected transient VaadinApplicationObjectSupport app;
    @Autowired
    private PropertyBAO propertyBAO;
    @Autowired
    private UICommonUtils uiCommonUtils;

    @Override
    public Map<String, Object> click(ClickEvent event) throws Exception {
	SearchMerchantProfileView searchMerchantProfileView = (SearchMerchantProfileView) this.getBasedComponent();

	Map<com.vaadin.ui.Component, Object> mapDefaultValue = new HashMap<com.vaadin.ui.Component, Object>();
	mapDefaultValue.put(searchMerchantProfileView.getTablePanel().getSortingTablePanel().getOpgSortingType1(),
		SearchCriteriaBean.DIRECTION_DESC);
	mapDefaultValue.put(searchMerchantProfileView.getTablePanel().getSortingTablePanel().getOpgSortingType2(),
		SearchCriteriaBean.DIRECTION_DESC);
	mapDefaultValue.put(searchMerchantProfileView.getTablePanel().getSortingTablePanel().getOpgSortingType3(),
		SearchCriteriaBean.DIRECTION_DESC);

	String typeDefault = this.propertyBAO.getPropertyValue("com.fw.ui.view.profile.SearchMerchantProfileView.default.type.item");
	String statusDefault = this.propertyBAO.getPropertyValue("com.fw.ui.view.profile.SearchMerchantProfileView.default.status.item");
	String hideMerchantTestDefault = this.propertyBAO
		.getPropertyValue("com.fw.ui.view.profile.SearchMerchantProfileView.default.hideMerchantTest");

	Boolean hideMerchantTestDefaultBoolean = true;
	if (hideMerchantTestDefault != null && !hideMerchantTestDefault.isEmpty()) {
	    hideMerchantTestDefaultBoolean = new Boolean(hideMerchantTestDefault);
	}

	mapDefaultValue.put(searchMerchantProfileView.getCbbStatus(), statusDefault);
	mapDefaultValue.put(searchMerchantProfileView.getCbbMerchantServiceType(), typeDefault);
	mapDefaultValue.put(searchMerchantProfileView.getCbHideMerchantTest(), hideMerchantTestDefaultBoolean);

	uiCommonUtils.clearAllUIComponentWithPrefixDefaultValue(searchMerchantProfileView, mapDefaultValue);
	return null;
    }

    @Override
    public boolean validate(ClickEvent event) {

	return true;
    }

}
